package com.ss.android.article.base.feature.detail.view;

import android.annotation.TargetApi;
import android.util.Pair;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.detail2.ArticleDetailWebPage;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.newmedia.f.Response;

import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;

@TargetApi(value = 11)
public final class MyWebViewClientV11 extends MyWebViewClient {
    public MyWebViewClientV11(ArticleDetailWebPage arg1) {
        super(arg1);
    }

    public final WebResourceResponse shouldInterceptRequest(WebView arg8, String arg9) {
        String v0_2;
        Object v1_1 = null;
        boolean v0 = false;
        WebResourceResponse v2 = null;
        if (TTUtils.isValidUrl(arg9)) {
            String v1 = this.e;
            if (!arg9.equals(v1)) {
                int v3 = arg9.indexOf(35);
                if (v3 > 0) {
                    int v4 = arg9.indexOf("tt_font=", v3);
                    if (v4 > v3) {
                        v0 = arg9.substring(0, v4 - 1).equals(v1);
                    }
                }

                if (!v0) {
                    return v2;
                }
            }

            if (Logger.debug()) {
                Logger.d("MyWebViewClientV11", "try interceptRequest " + arg9);
            }

            long v4_1 = System.currentTimeMillis();
            Object v0_1 = this.mArticleDetailWebPageRef.get();
            Response v3_1 = v0_1 != null ? ((ArticleDetailWebPage) v0_1).checkResponse(arg9) : null;
            if (v3_1 != null && v3_1.responseCode == 200 && v3_1.bytes != null && v3_1.bytes.length > 0) {
                Pair v6 = NetworkUtils.parseContentType(v3_1.contentType);
                if (v6 != null) {
                    v0_1 = v6.first;
                    if (v6.second != null && (Charset.isSupported((String) v6.second))) {
                        v1_1 = v6.second;
//                        goto label_52;
                    } else {
                        v1_1 = null;
                    }
                } else {
                    v1_1 = null;
                    v0_1 = null;
                }

//                label_52:
                v2 = new WebResourceResponse(((String) v0_1), ((String) v1_1), new ByteArrayInputStream(v3_1.bytes));
            }

            if (!Logger.debug()) {
                return v2;
            }

            v4_1 = System.currentTimeMillis() - v4_1;
            v0_2 = v2 != null ? "hit memory cache" : "miss";
            Logger.d("MyWebViewClientV11", "interceptRequest take " + v4_1 + " ms " + arg9 + " " + v0_2);
        }

        return v2;
    }
}

